
$(function() {
	Tip.emp('负责人');
	
	$("select[id^='account_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
	
	$("select[id^='bank_s']:visible").multiselect({
		minWidth: 140,
		selectedList: 4
	}).multiselect("uncheckAll");
	
	$("select[id^='ab_s']:visible").change(function() {
		var s = $(this).val();
		// alert(s);
		if (s == '1') {			
			$("select[id^='status_s']").multiselect("widget").find(":checkbox").each(function() {
				var a = $(this).val();
				if ($(this).attr("checked")) {
					this.click();
				}
				
				if (a == '1') {
					this.click();
				}
			});
			
			$("select[id^='orderby_s']:visible").attr("value", '-');
			$("select[id^='desc_s']:visible").attr("value", '2');
		} else if (s == '2') {
			$("select[id^='status_s']").multiselect("widget").find(":checkbox").each(function() {
				var a = $(this).val();
				if ($(this).attr("checked")) {
					this.click();
				}
				
				if (a == '4') {
					this.click();
				}
			});
			
			$("select[id^='orderby_s']:visible").attr("value", '2');
			$("select[id^='desc_s']:visible").attr("value", '2');
		} else if (s == '3') {
			$("select[id^='status_s']").multiselect("widget").find(":checkbox").each(function() {
				var a = $(this).val();
				if ($(this).attr("checked")) {
					this.click();
				}
				
				if (a == '5' || a == '8') {
					this.click();
				}
			});
			
			$("select[id^='pagesize_s']:visible").attr("value", '50');
		} else {
			$("select[id^='status_s']").multiselect("widget").find(":checkbox").each(function() {
				var a = $(this).val();
				if ($(this).attr("checked")) {
					this.click();
				}
				
				if (a == '2') {
					this.click();
				}
			});
			
			$("select[id^='orderby_s']:visible").attr("value", 't2');
			$("select[id^='desc_s']:visible").attr("value", '1');
			$("select[id^='pagesize_s']:visible").attr("value", '15');
		}
	});
});

var Invest = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.emp = form.emp.value;
				body.account = form.account.value;
				body.bank = form.bank.value;
				body.venture = form.venture.value;
				
				body.name = form.name.value;
				body.type = form.type.value;
				
				body.amount = form.amount.value;
				body.currency = form.currency.value;
	
				body.yield = form.yield.value;
				body.bonus = form.bonus.value;
				
				body.date = form.date.value;
				body.t1 = form.date1.value;
				body.t2 = form.date2.value;
				body.day = form.day.value;
								
				body.content = form.content.value;
	
				$(this).dialog("close");
				
				$.post('finance.php?do=Invest.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},

	popup: function (e, p2, id) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var a1 = ['编辑信息', 'url', 'Invest.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];		
		
		var c1 = 'finance.php?do=Invest.edit&id=' + id;
		var c2 = 'finance.php?do=Invest.view&id=' + id;		

		var s = c1 + ", " + c2;

		this.popup_(e, [a1, a2], s);
	},
	
	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var c3 = 'finance.php?do=Invest.copy&id=' + id;
		var a3 = ['复制信息', 'url', 'Invest.dialog_copy_', '650x420'];
		
		var ss = 'finance.php?do=Invest.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Invest.dialog_ss', '400x200'];
		
		s += ", " + c3 + ", " + ss;
		a.push(a3);
		a.push(bb);
		
		return popup(e, a, s);
	},

	/**
	 * 修改状态
	 */
	dialog_ss: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('finance.php?do=Invest.audit&item=147', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'finance.php?do=Invest.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
	
				var form = $("#form_edit")[0];
	
				var body = {};
				body.id = form.id.value;
				body.emp = form.emp.value;
				body.account = form.account.value;
				body.venture = form.venture.value;
				
				body.bank = form.bank.value;
				body.name = form.name.value;
				body.type = form.type.value;
				
				body.amount = form.amount.value;
				body.currency = form.currency.value;
	
				body.yield = form.yield.value;
				body.bonus = form.bonus.value;
				
				body.date = form.date.value;
				body.t1 = form.date1.value;
				body.t2 = form.date2.value;
				body.day = form.day.value;
								
				body.content = form.content.value;
	
				$(this).dialog("close");
	
				var url = 'finance.php?do=Invest.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}
	
				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_edit(url, title, xy);
	},
	
	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {			
			"关闭": function() {
				$(this).dialog("close");
			},
	
			"复制": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];
	
				var body = { };
				body.emp = form.emp.value;
				body.account = form.account.value;
				body.venture = form.venture.value;
				
				body.bank = form.bank.value;
				body.name = form.name.value;
				body.type = form.type.value;
				
				body.amount = form.amount.value;
				body.currency = form.currency.value;
	
				body.yield = form.yield.value;
				body.bonus = form.bonus.value;
				
				body.date = form.date.value;
				body.t1 = form.date1.value;
				body.t2 = form.date2.value;
				body.day = form.day.value;
								
				body.content = form.content.value;
	
				$(this).dialog("close");
				
				$.post('finance.php?do=Invest.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});
	
		dialog_add(url, title, xy);
	},
	
	popup_all: function (e, p2) {
		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'finance.php?do=Invest.delete' + p2;		
		var c2 = 'finance.php?do=Invest.xls' + p2;
			
		var a1 = ['删除信息', 'url', 'Common.list_delete'];		
		var a2 = ['导出Excel', 'url', 'jswin', '1024x768'];

		var s = c1 + ", " + c2;

		return popup(e, [a1, a2], s);
	}
};
